package se392.ateam2006.user;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * Entity class to define the attributes and operations of a User (name, email, etc)
 * This information can then be persisted into a database
 * @author Ateam (Matthew Bennett, Claire Melton, Shingai Manyiwa, John Adderley)
 * @version 25/03/07
 */
@Entity
public class UserEntity implements Serializable {
    
    @Id
    private String email;
    private String forename;
    private String surname;
    
    /**
     * Default constructor required as this is an entity class
     */
    public UserEntity() {}
    
    /**
     * Create a new UserEntity
     * @param email - String, the email address of the user
     */
    public UserEntity(String email){
        this.email = email;
    }
    
    /**
     * Create a new UserEntity
     * @param email - String, the email address of the user
     * @param forename - String, the first name of the user
     * @param surname - String, the surname of the user
     */
    public UserEntity(String email,String forename, String surname) {
        this.email = email;
        this.forename = forename;
        this.surname = surname;
    }
    
    /**
     * Get the email address of the user
     * @return String - the user's email
     */
    public String getEmail() {
        return email;
    }
    
    /**
     * Set the email address of the user
     * @param email - String, the user's email address
     */
    public void setEmail(String email) {
        this.email = email;
    }
    
    /**
     * Get the first name of the user
     * @return String - the user's first name
     */
    public String getForename() {
        return forename;
    }
    
    /**
     * Set the first name of the user
     * @param email - String, the user's first name
     */
    public void setForename(String forename) {
        this.forename = forename;
    }
    
    /**
     * Get the surname of the user
     * @return String - the user's surname
     */
    public String getSurname() {
        return surname;
    }
    
    /**
     * Set the surname of the user
     * @param email - String, the user's surname
     */
    public void setSurname(String surname) {
        this.surname = surname;
    }
    
    /**
     * Override the equals method...
     * @param other - Object, the object to compare to
     * @return boolean - are the objects equal?
     */
    public boolean equals(Object other) {
        
        if(!(other instanceof UserEntity)){
            return false;
        } else{
            
            UserEntity user = (UserEntity)other;
            if(this.getEmail().equals(user.getEmail())) {
                return true;
            }else{
                return false;
            }
        }
    }  
}
